/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.game.display;

import deatax.math.Vector3;
import java.util.ArrayList;

/**
 *
 * @author pson
 */
public class Location {
    
    private Vector3 current;
    private Vector3 initial;
    private Vector3 target;
    private Vector3 targetVector;
    private Vector3 movement;
    
    private float initSpeed;
    private float maxSpeed;
    private Easing easing;
    private float acceleration;
    
    private ArrayList<LocationListener> listeners;
    
    public Vector3 current() {
        return current;
    }
    
    public Vector3 target() {
        return target;
    }
    
    public Vector3 movement() {
        return movement;
    }
    
    public void clearTarget() {
        this.initial = null;
        this.target = null;
        this.targetVector = null;
    }
    
    public void setTarget(Vector3 target) {
        this.initial = new Vector3(current);
        this.target = target;
        this.targetVector = this.target.subtract(this.current);
    }
    
    public void addTarget(Vector3 target) {
        if (this.target != null) {
            target = this.target.add(target);
        }
        setTarget(target);
    }
    
    public void update(long time) {
        if (target != null) {
            Vector3 c_vec = current.subtract(initial);
            
            float mag = 1.0f;
            float p = c_vec.length() / targetVector.length();
            if (easing != null) {
                mag = easing.getFactor(p);
            }
            
            float c_spd = maxSpeed * mag;
            
            this.current.add(c_vec);
        }
    }
}
